using System.Collections.Generic;
using System.Linq;
using Magiq.Tests.Sql.TestModel;
using Magiq.Tests.Support;
using NUnit.Framework;

namespace Magiq.Tests.Sql
{
    [TestFixture]
    public class MagiqToSqlInsertsInheritanceTest : BaseMagiqProviderInsertsInheritanceTest<LinqToSqlTestSuperClass, LinqToSqlTestSubClass>
    {
        protected override IMagiqTestConfigurator GetConfigurator()
        {
            return MagiqToSqlTestConfigurator.Current;
        }

        private static IQueryable<LinqToSqlTestClass> GetList()
        {
            return new List<LinqToSqlTestClass>
                       {
                           new LinqToSqlTestClass
                               {
                                   StringProperty = "bla",
                                   IntProperty = 4
                               },
                           new LinqToSqlTestClass
                               {
                                   StringProperty = "ble",
                                   IntProperty = 4
                               }
                       }.AsQueryable();
        }

        [Test]
        public virtual void ShouldNotTryToInsertIntoAList()
        {
            GetList().Insert(TestClassInstances.Select(x => new LinqToSqlTestClass
                                                                      {
                                                                          AnotherStringProperty = x.StringProperty,
                                                                          IntProperty = x.AnotherIntProperty,
                                                                          AnotherIntProperty = 4,
                                                                          StringProperty = "lala"
                                                                      }));

            MagiqMock.AssertWasUsed();
        }

        [Test]
        public void ShouldInsertRegularListIntoLinqToSql()
        {
            Destination.Insert(GetList().Select(x => new LinqToSqlTestSubClass
                                                        {
                                                            AnotherStringProperty = x.StringProperty,
                                                            IntProperty = x.AnotherIntProperty,
                                                            AnotherIntProperty = 4,
                                                            StringProperty = "lala",
                                                            InheritorProperty = "bla"
                                                        }));
        }
    }
}